//
//  ProjectSeletedCell.m
//  XiaoMiao
//
//  Created by kinglian_iOS_000 on 2018/1/30.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "ProjectSeletedCell.h"
#import "ProjectSeletedCollectionViewCell.h"
#import "ProjectSeletedModel.h"

@interface ProjectSeletedCell () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, ProjectSeletedCollectionViewCellDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UILabel *proNameLabel;
@end

@implementation ProjectSeletedCell

- (void)awakeFromNib {
    [super awakeFromNib];
 
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(ProjectSeletedCollectionViewCell.class) bundle:nil] forCellWithReuseIdentifier:[ProjectSeletedCollectionViewCell cellId]];
}

- (void)setProjectSeletedModel:(ProjectSeletedModel *)projectSeletedModel {
    _projectSeletedModel = projectSeletedModel;
    
    self.proNameLabel.text = projectSeletedModel.name;
    
    [self.collectionView reloadData];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.projectSeletedModel.cateViews.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ProjectSeletedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[ProjectSeletedCollectionViewCell cellId] forIndexPath:indexPath];
    
    cell.projectSeletedModel = self.projectSeletedModel.cateViews[indexPath.item];
    cell.item = indexPath.item;
    cell.delegate = self;
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // llq todo
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [ProjectSeletedCollectionViewCell cellSize];
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0.01;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0.01;
}

#pragma mark - ProjectSeletedCollectionViewCellDelegate
- (void)projectSeletedCollectionViewCell:(ProjectSeletedCollectionViewCell *)projectSeletedCollectionViewCell seletedItem:(NSInteger)seletedItem {
    if (seletedItem > self.projectSeletedModel.cateViews.count) {
        return;
    }
    
    if ([self.delegate respondsToSelector:@selector(projectSeletedCell:projectSeletedModel:seletedCollectionCellItem:)]) {
        [self.delegate projectSeletedCell:self projectSeletedModel:self.projectSeletedModel seletedCollectionCellItem:seletedItem];
    }
}

#pragma mark - Public
+ (CGFloat)topViewHeight {
    return 30.f;
}
+ (NSString *)cellId {
    return @"_kProjectSeletedCelld_";
} 

@end
